﻿// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.ApplicationModel.Core;
using Microsoft.UI.Xaml.Media.Animation;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace SerialCommand
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class WavePages : Page
    {
        public WavePages()
        {
            this.InitializeComponent();
            ContentFrame.Navigate(typeof(BlankPage1));
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var currentWindow = WindowHelper.GetWindowForElement(this);
            currentWindow.Title = "波形绘制";
            currentWindow.ExtendsContentIntoTitleBar = true;
            AppTitleBar.Height = 30;
            AppTitleBar.MinWidth = 188;
            AppTitleBar.VerticalAlignment = VerticalAlignment.Top;
            currentWindow.SetTitleBar(AppTitleBar);
        }
        public void AddTabToTabs(TabViewItem tab)
        {
            Tabs.TabItems.Add(tab);
        }
        private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
        {
            // To ensure that the tabs in the titlebar are not occluded by shell
            // content, we must ensure that we account for left and right overlays.
            // In LTR layouts, the right inset includes the caption buttons and the
            // drag region, which is flipped in RTL.

            // The SystemOverlayLeftInset and SystemOverlayRightInset values are
            // in terms of physical left and right. Therefore, we need to flip
            // then when our flow direction is RTL.
            if (FlowDirection == FlowDirection.LeftToRight)
            {
                AppTitleBar.MinWidth = sender.SystemOverlayRightInset;
                ShellTitleBarInset.MinWidth = sender.SystemOverlayLeftInset;
            }
            else
            {
                AppTitleBar.MinWidth = sender.SystemOverlayLeftInset;
                ShellTitleBarInset.MinWidth = sender.SystemOverlayRightInset;
            }

            // Ensure that the height of the custom regions are the same as the titlebar.
            AppTitleBar.Height = ShellTitleBarInset.Height = sender.Height;
        }

        private void Tabs_AddTabButtonClick(TabView sender, object args)
        {
            TabViewItem tabViewItem = new TabViewItem();
            tabViewItem.VerticalAlignment = VerticalAlignment.Stretch;
            tabViewItem.HorizontalAlignment = HorizontalAlignment.Stretch;
            var page = new CanvasPage();
            page.VerticalAlignment = VerticalAlignment.Stretch;
            page.HorizontalAlignment = HorizontalAlignment.Stretch;
            tabViewItem.Content = page;
            tabViewItem.Header = "波形打印";
            AddTabToTabs(tabViewItem);
        }

        private void Tabs_TabCloseRequested(TabView sender, TabViewTabCloseRequestedEventArgs args)
        {
            sender.TabItems.Remove(args.Tab);
        }
        enum FrameStep
        {
            Init,
            Lark,
        }
        FrameStep step = FrameStep.Lark;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (((string)(sender as Button).Tag).Equals("Up"))
                step--;
            else
                step++;
            if (step < FrameStep.Init)
            {
                step = FrameStep.Init;
                return;
            }
            if (step > FrameStep.Lark)
            {
                step = FrameStep.Lark;
                return;
            }
            switch (step)
            {
                case FrameStep.Init:
                    ContentFrame.Navigate(typeof(LarkTestPage), null, new SlideNavigationTransitionInfo()
                    {
                        Effect = SlideNavigationTransitionEffect.FromLeft
                    });
                    break;
                case FrameStep.Lark:
                    ContentFrame.Navigate(typeof(BlankPage1), null, new SlideNavigationTransitionInfo()
                    {
                        Effect = SlideNavigationTransitionEffect.FromRight
                    });
                    break;
            }
        }
    }
}
